#{extends 'Users/frame.html' /}

#{set 'moreStyles'}
<link rel="stylesheet" type="text/css" media="screen" href="@{'/public/stylesheets/Users/edit.scss'}" />
<link rel="stylesheet" type="text/css" media="screen" href="@{'/public/stylesheets/navigationbar.scss'}" />
<link rel="stylesheet" type="text/css" media="screen" href="@{'/public/stylesheets/Users/commodity.scss'}" />
<link rel="stylesheet" type="text/css" media="screen" href="@{'/public/pager/Pager.css'}" />
<link rel="stylesheet" type="text/css" media="screen" href="@{'/public/stylesheets/Users/order.scss'}" />
#{/set}
#{set 'moreScripts'}
<script src="@{'/public/pager/jquery.pager.js'}" type="text/javascript" charset="utf-8"></script>
#{/set}
<script language="javascript">
//左边列表选中状态。
$(function(){
	$("#mi_order").addClass("menu-select");
});
</script>
<div class="navigationBar">
	<table>
		<tr>
			<td><img src="@{'/public/images/navigationHouse.gif'}"></td>
			<td><strong>当前位置：</strong></td>
			<td>
				<a href="/">首页</a>
				>>
				<a href="/users">会员中心</a>
				>>
				<font class="current">订单管理</font>
			</td>
		</tr>
	</table>
</div>
<script language="javascript">
	$(function(){
		//初始化翻页控件。
		$("#pager").pager(
			{
				pagenumber: ${queryBean.currentPage}, 
				pagecount: ${queryBean.totalPage}, 
				totalcount: ${queryBean.totalQuantity},
				buttonClickCallback: PageClick 
			}
		);
	});
	//翻页功能。
	PageClick = function(pageclickednumber) {
		$("#currentPage").val(pageclickednumber);
		doSearch();
	}
	
	function doSearch() {
		$("#form1").submit();
	}
</script>
</table>
<div id="edit-comment">
	<div id="errMsg" class="error">
		${errMsg}
		#{error 'errMsg'/}
	</div>
	<table class="commodity-query">
		#{form @users.order(), name:'form1', id:'form1'}
			<input type="hidden" id="currentPage" name="queryBean.currentPage" value="${queryBean.currentPage}">
			每页
			<select name="queryBean.quantityEachPage" onchange="doSearch()">
				<option value="2" #{if queryBean.quantityEachPage==2} selected #{/if}>2</option>
				<option value="10" #{if queryBean.quantityEachPage==10} selected #{/if}>10</option>
				<option value="25" #{if queryBean.quantityEachPage==25} selected #{/if}>25</option>
				<option value="50" #{if queryBean.quantityEachPage==50} selected #{/if}>50</option>
			</select>
			条记录
		#{/form}
	</table>
	<table class="commodity-table">
		<thead>
			<tr>
				<th>合并</th>
				<th>订单编号</th>
				<th>下单时间</th>
				<th>订单总额</th>
				<th>收货人</th>
				<th>订单状态</th>
				<th>操作</th>
			</tr>
		</thead>
		#{if orders}
			#{list items:orders, as:'order'}
			<tr>
				<td>
					<input class="megerIds" type="checkbox" value="${order.id}">
				</td>
				<td><a href="@{Orders.orderDetail(order.id)}">${order.id}</a></td>
				<td>${order.createAt.format("yyyy-MM-dd hh:mm:ss")}</td>
				<td><span class="price">${order.totalPrice}</span>&nbsp;元</td>
				<td>${order.receiver}</td>
				<td>
					<span class="important">
						#{if order.orderStatus == models.Order.OrderStatus.NEW}
							新订单，可发汇款确认
						#{/if}
						#{if order.orderStatus == models.Order.OrderStatus.PAID}
							已付款，等待客服确认
						#{/if}
						#{if order.orderStatus == models.Order.OrderStatus.PAY_CONFIRM}
							付款已认，等待发货
						#{/if}
						#{if order.orderStatus == models.Order.OrderStatus.SENDED}
							已发货
						#{/if}
						#{if order.orderStatus == models.Order.OrderStatus.HISTORY}
							历史订单
						#{/if}
						#{if order.orderStatus == models.Order.OrderStatus.FAIL}
							订单作废
						#{/if}
					</span>
				</td>
				<td>
					<a class="editer" href="@{Orders.orderDetail(order.id)}">[详细]</a>&nbsp;
					#{if order.orderStatus == models.Order.OrderStatus.NEW}
						<a class="editer" href="@{orders.editOrderItems(order.id)}">[编辑]</a>&nbsp;
						<a class="editer" href="@{orders.remittanceConfirm(order.id)}">[汇款确认]</a>&nbsp;
					#{/if}
				</td>
			</tr>
			#{/list}
		#{/if}
		#{else}
			<tr>
				<td colspan="6">没找到记录。</td>
			</tr>
		#{/else}
	</table>
	<div>
		<input type="button" class="button1" value="合并订单" onClick="megerOrders()">
	</div>
	<div id="pager"></div>
	#{form @orders.megerOrders(), name:'form2', id:'form2'}
		<input type="hidden" id="idA" name="idA" value="">
		<input type="hidden" id="idB" name="idB" value="">
	#{/form}
	<script language="javascript">
	function megerOrders(){
		var ids = [];
		var idCkeBoxes = $(".megerIds");
		if(idCkeBoxes || idCkeBoxes.length > 0) {
			for(var i=0 ; i<idCkeBoxes.length ; i++) {
				if(idCkeBoxes[i].checked == true) {
					ids.push(idCkeBoxes[i].value);
				}
			}
		}
		if(ids.length != 2) {
			var errMsg = "请选择 两条 新订单记录进行合并。";
			$("#errMsg").html(errMsg);
			alert(errMsg);
			return;
		}
		$("#idA").val(ids[0]);
		$("#idB").val(ids[1]);
		$("#form2").submit();
		//var dataStr = "idA="+ids[0]+"&idB="+ids[1];
		/*$.ajax({
			url: "@{orders.megerOrders()}",
			data: dataStr,
			type: "POST",
			dataType: "json",
			complete: function(XMLHttpRequest, textStatus, errorThrown) {
				if(textStatus == "error") {
					var errJson = eval("("+XMLHttpRequest.responseText+")");
					var errMsg = "操作失败，"+errJson.message;
					$("#errMsg").html(errMsg);
					alert(errMsg);
				}
			}
		});*/
	}
	</script>
</div>